package com.breaktian.demoapp.ui.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.breaktian.assemble.customviews.tableview.TableView;
import com.breaktian.demoapp.R;
import com.breaktian.demoapp.provider.TestProvider;
import com.breaktian.demoapp.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * 我的
 */
public class MineFragment extends BaseFragment<TestProvider> {


    private View rootView;
    private TableView tableView;

    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        rootView = inflater.inflate(R.layout.fragment_mine, container, false);
        initView();
        return rootView;
    }

    private void initView() {
        rootView.findViewById(R.id.fold).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tableView.foldRemainRows(2);
            }
        });
        rootView.findViewById(R.id.unfold).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tableView.unfold();
            }
        });
        tableView = (TableView)rootView.findViewById(R.id.tableView);
        final List<String> list = new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add("测试数据"+i);
        }
        TableView.TableAdapter tableAdapter = new TableView.TableAdapter() {
            @Override
            public View getItemView(Context context, Object itemObj, int position) {
                String s = list.get(position);
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_tableview,null);
                TextView tv = view.findViewById(R.id.textView2);
                tv.setText(s);
                return view;
            }
        };
        TableView.TableAdapter.ItemClickListener listener = new TableView.TableAdapter.ItemClickListener() {
            @Override
            public void onClick(Object o, int pos, View v) {
                String s = (String)o;
                ToastUtils.show("onClick:"+s);
            }

            @Override
            public void onLongClick(Object o, int pos, View v) {
                String s = (String)o;
                ToastUtils.show("onLongClick:"+s);
            }
        };
        tableView.init(tableAdapter, 3, list, listener);


    }

    @Override
    protected TestProvider getProvider() {
        return null;
    }
}
